/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2019-02-13 Time: 23:07
 */

import {Action} from "../../../configuration/ActionCreator"
import {FetchStatus, RequestAction, RequestMethod} from "../../../configuration/RequestConfiguration";
import {AppRequestPath} from "../../../configuration/AppConfig";
import {API_PROCEDURE2} from "../../../constant/API";
import global from "../../../configuration/global";

//------------------------------获取班次时间表----------------------------------
export const RetrieveWhskShiftsSetup = 'RetrieveWhskShiftsSetup';
export const retrieveWhskShiftsSetup = (str) => {
    let action = Action(RetrieveWhskShiftsSetup);
    return dispatch => dispatch(request_retrieveWhskShiftsSetup(action, str))
};

export const request_retrieveWhskShiftsSetup = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'RetrieveWhskShiftsSetup',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onRetrieveWhskShiftsSetup = (state = {}, action) => {
    switch (action.type) {
        case RetrieveWhskShiftsSetup: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


//------------------------------获取值班人员----------------------------------
export const RetrieveWhskShifts = 'RetrieveWhskShifts';
export const retrieveWhskShifts = (str) => {
    let action = Action(RetrieveWhskShifts);
    return dispatch => dispatch(request_retrieveWhskShifts(action, str))
};

export const request_retrieveWhskShifts = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            "hotelId": global.hotelId,
            "fu": "ExecRetrieveJson",
            "jn": {
                "where": {
                    "1": "1"
                },
                "fileds": {
                    "fileds": ["opdate","shift","wuserid","place","place_c","crdate","userid","log_ncard","log_user","describ","position"]
                },
                "table": {
                    "table": "viewJqGrid_whsk_shifts_arrange"
                },
                "wherestring": ["@@WS", "opdate="+str+""]
            },
            "jnJson2": "{}",
        },
        action
    )
};

export const onRetrieveWhskShifts = (state = {}, action) => {
    switch (action.type) {
        case RetrieveWhskShifts: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


//------------------------------班次时间设置----------------------------------
export const WHSKShiftsSetupAdd = 'WHSKShiftsSetupAdd';
export const wHSKShiftsSetupAdd = (str) => {
    let action = Action(WHSKShiftsSetupAdd);
    return dispatch => dispatch(request_shiftsSetupAdd(action, str))
};

export const request_shiftsSetupAdd = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKShiftsSetupAdd',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onWHSKShiftsSetupAdd = (state = {}, action) => {
    switch (action.type) {
        case WHSKShiftsSetupAdd: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


//------------------------------添加值班人员默认值----------------------------------
export const RetrieveWHSKShiftsArrangeDefault = 'RetrieveWHSKShiftsArrangeDefault';
export const retrieveWHSKShiftsArrangeDefault = (str) => {
    let action = Action(RetrieveWHSKShiftsArrangeDefault);
    return dispatch => dispatch(request_WHSKShiftsArrangeDefault(action, str))
};

export const request_WHSKShiftsArrangeDefault = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKShiftsArrangeDefault',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onWHSKShiftsArrangeDefault = (state = {}, action) => {
    switch (action.type) {
        case RetrieveWHSKShiftsArrangeDefault: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

//------------------------------添加值班人员----------------------------------
export const ShiftsArrangeAdd = 'ShiftsArrangeAdd';
export const shiftsArrangeAdd = (str) => {
    let action = Action(ShiftsArrangeAdd);
    return dispatch => dispatch(request_shiftsArrangeAdd(action, str))
};

export const request_shiftsArrangeAdd = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKShiftsArrangeAdd',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onShiftsArrangeAdd = (state = {}, action) => {
    switch (action.type) {
        case ShiftsArrangeAdd: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

//------------------------------修改值班人员----------------------------------
export const ShiftsArrangeEdit = 'ShiftsArrangeEdit';
export const shiftsArrangeEdit = (str) => {
    let action = Action(ShiftsArrangeEdit);
    return dispatch => dispatch(request_shiftsArrangeEdit(action, str))
};

export const request_shiftsArrangeEdit = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKShiftsArrangeEdit',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onShiftsArrangeEdit = (state = {}, action) => {
    switch (action.type) {
        case ShiftsArrangeEdit: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

//------------------------------删除值班人员----------------------------------
export const ShiftsArrangeDel = 'ShiftsArrangeDel';
export const shiftsArrangeDel = (str) => {
    let action = Action(ShiftsArrangeDel);
    return dispatch => dispatch(request_shiftsArrangeDel(action, str))
};

export const request_shiftsArrangeDel = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKShiftsArrangeDel',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onShiftsArrangeDel = (state = {}, action) => {
    switch (action.type) {
        case ShiftsArrangeDel: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


